home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / v cisle / htttrack / httrack-3.41-3.exe / {app} / src_win / WinHTTrack / Iplog.cpp < prev    next >
C/C++ Source or Header  |  2006-08-15  |  9KB  |  383 lines

  1. // iplog.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Shell.h"
  6. #include "iplog.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. extern "C" {
  15.   #include "HTTrackInterface.h"
  16. }
  17. extern HICON httrack_icon;
  18.  
  19. // Helper
  20. extern LaunchHelp* HtsHelper;
  21.  
  22. #define LOW_MARK 127000
  23. #define HIGH_MARK 128000
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // Ciplog dialog
  27.  
  28.  
  29. Ciplog::Ciplog(CWnd* pParent /*=NULL*/)
  30.     : CDialog(Ciplog::IDD, pParent)
  31. {
  32.   timer=0;
  33.   txt="\n";
  34.   type=-1;
  35.   type_filter=0;
  36.   filter=0;
  37.     //{{AFX_DATA_INIT(Ciplog)
  38.     m_iplog = _T("");
  39.     //}}AFX_DATA_INIT
  40. }
  41.  
  42.  
  43. void Ciplog::DoDataExchange(CDataExchange* pDX)
  44. {
  45.     CDialog::DoDataExchange(pDX);
  46.     //{{AFX_DATA_MAP(Ciplog)
  47.     DDX_Control(pDX, IDC_HIDEINFO, m_ctl_hideinfo);
  48.     DDX_Control(pDX, IDC_log, m_ctl_iplog);
  49.     DDX_Text(pDX, IDC_log, m_iplog);
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53.  
  54. // typedef void (AFX_MSG_CALL CCmdTarget::*AFX_PMSG)(void);
  55. BEGIN_MESSAGE_MAP(Ciplog, CDialog)
  56.     //{{AFX_MSG_MAP(Ciplog)
  57.     ON_EN_VSCROLL(IDC_log, OnScroll)
  58.     ON_WM_DESTROY()
  59.     ON_WM_SIZE()
  60.     ON_WM_HELPINFO()
  61.     ON_BN_CLICKED(IDC_changelog, Onchangelog)
  62.     ON_WM_TIMER()
  63.     ON_CBN_SELCHANGE(IDC_HIDEINFO, OnSelchangeHideinfo)
  64.     ON_EN_HSCROLL(IDC_log, OnScroll)
  65.     ON_BN_CLICKED(IDC_FIND, OnFind)
  66.     //}}AFX_MSG_MAP
  67.   ON_COMMAND(ID_HELP_FINDER,OnHelpInfo2)
  68.   ON_COMMAND(ID_HELP,OnHelpInfo2)
  69.     ON_COMMAND(ID_DEFAULT_HELP,OnHelpInfo2)
  70.   ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  71. END_MESSAGE_MAP()
  72.  
  73. /////////////////////////////////////////////////////////////////////////////
  74. // Ciplog message handlers
  75.  
  76.  
  77. // refresh
  78. void Ciplog::AffLogRefresh() {
  79.      char catbuff[CATBUFF_SIZE];
  80.  
  81.   if (wait_me) {
  82.     wait_me=0;
  83.     return;
  84.   }
  85.   if (type_log != type) {
  86.     type=type_log;
  87.     if (fp)
  88.       fclose(fp);
  89.     fp=NULL;
  90.   }
  91.   if (type_filter != filter) {
  92.     filter=type_filter;
  93.     if (fp)
  94.       fclose(fp);
  95.     fp=NULL;
  96.   }
  97.   
  98.   if (fp==NULL) {
  99.     txt="";
  100.     if (type_log) {
  101.       fp=fopen(fconcat(catbuff,pathlog,"hts-log.txt"),"rb");
  102.       SetWindowTextCP(this, LANG_E10);
  103.       SetWindowTextCP(m_ctl_iplog, LANG_E10);
  104.       SetDlgItemTextCP(this, IDC_changelog,LANG_E11);
  105.     }
  106.     else {
  107.       fp=fopen(fconcat(catbuff,pathlog,"hts-err.txt"),"rb");
  108.       SetWindowTextCP(this, LANG_E11);
  109.       SetWindowTextCP(m_ctl_iplog, LANG_E11);
  110.       SetDlgItemTextCP(this, IDC_changelog,LANG_E10);
  111.       if (!fp) {        /* pas de err : switcher (en cas de log unique) */
  112.         type_log=1;
  113.         GetDlgItem(IDC_changelog)->ModifyStyle(0,WS_DISABLED);
  114.       }
  115.     }
  116.     SetDlgItemTextCP(this, IDC_log,txt);
  117.   }
  118.   
  119.   if (fp) {
  120.     char dat[HIGH_MARK+4]; dat[0]='\0';
  121.     clearerr(fp);
  122.     if (!feof(fp)) {
  123.       char* a=dat;
  124.       char* startline=dat;
  125.       int n=0;
  126.       int c;
  127.       while ( (!feof(fp)) && (n<HIGH_MARK) ) {
  128.         c = fgetc(fp);
  129.         n++;
  130.         if ((c>0) && (c!=EOF)) {
  131.           switch(c) {
  132.           case 13: break;
  133.           case 10: {
  134.             *a='\0';
  135.             if (filter & 1) {
  136.               if (strstr(startline,"Debug:")) {       // Θliminer dΘbug
  137.                 a=startline;
  138.               }
  139.             }
  140.             if (filter & 2) {
  141.               if (strstr(startline,"Info:")) {       // Θliminer info
  142.                 a=startline;
  143.               }
  144.             }
  145.             if (a!=startline) {
  146.               *a++=13; 
  147.               *a++=10;
  148.             }
  149.             startline=a;
  150.             /* couper en fin de ligne */
  151.             if (n>=LOW_MARK)
  152.               n=HIGH_MARK;
  153.                    }
  154.             break;
  155.           case 9: *a++=' '; break;
  156.           default:
  157.             *a++=c;
  158.             break;
  159.           }
  160.         }
  161.       }
  162.       *a='\0';
  163.     }
  164.     if (strlen(dat)>0) {
  165.       // avant d'Θcrire on sauvegarde la position (bah oui.. c chiant)
  166.       txt += dat;
  167.       int lh = m_ctl_iplog.GetScrollPos(SB_HORZ);
  168.       int lv = m_ctl_iplog.GetScrollPos(SB_VERT);
  169.       SetDlgItemTextCP(this, IDC_log,txt);
  170.       m_ctl_iplog.SetScrollPos(SB_HORZ,lh);
  171.       m_ctl_iplog.SetScrollPos(SB_VERT,lv);
  172.     }
  173.   }
  174. }
  175.  
  176. BOOL Ciplog::DestroyWindow() 
  177. {
  178.   StopTimer();
  179.   if (fp)
  180.     fclose(fp);
  181.   fp=NULL;
  182.     return CDialog::DestroyWindow();
  183. }
  184.  
  185. void Ciplog::OnScroll() 
  186. {
  187.   wait_me=1;  // attendre pour le scrolling
  188. }
  189.  
  190. BOOL Ciplog::OnInitDialog() 
  191. {
  192.   wait_me=0;
  193.   fp=NULL;
  194.  
  195.     CDialog::OnInitDialog();    
  196.   SetIcon(httrack_icon,false);
  197.   SetIcon(httrack_icon,true);
  198.   EnableToolTips(true);     // TOOL TIPS
  199.   SetForegroundWindow();   // yop en premier plan!
  200.   //m_ctl_iplog.ModifyStyle(WS_DLGFRAME,WS_CAPTION|WS_BORDER);
  201.   ///m_ctl_iplog.ModifyStyle(WS_DLGFRAME,WS_BORDER);
  202.   ///m_ctl_iplog.ModifyStyleEx(0,WS_EX_CLIENTEDGE|WS_EX_DLGMODALFRAME);
  203.   //m_ctl_iplog.SetReadOnly(FALSE);     // en blanc
  204.  
  205.   // Patcher l'interface pour les Franτais ;-)
  206.   if (LANG_T(-1)) {    // Patcher en franτais
  207.     //SetDlgItemTextCP(this, ,"");
  208.     SetDlgItemTextCP(this, IDC_STATIC_type,LANG(LANG_E4)); // "Type d'infos:");
  209.     SetDlgItemTextCP(this, IDC_logtype,LANG(LANG_E5)); // "Erreurs");
  210.     SetDlgItemTextCP(this, IDC_logtype2,LANG(LANG_E6)); // "Infos");
  211.     SetDlgItemTextCP(this, IDC_FIND,LANG(LANG_E7)); // "Find");
  212.     //SetDlgItemTextCP(this, IDOK,LANG(LANG_CLOSE)); // "FERMER");
  213.     SetCombo(this,IDC_HIDEINFO,LISTDEF_2);
  214.   }
  215.  
  216.   // dΘmarrer timer
  217.   StartTimer();
  218.  
  219.     return TRUE;  // return TRUE unless you set the focus to a control
  220.                   // EXCEPTION: OCX Property Pages should return FALSE
  221. }
  222.  
  223. // Resize
  224. void Ciplog::OnSize(UINT nType, int cx, int cy) 
  225. {
  226.   CDialog::OnSize(nType, cx, cy);
  227.  
  228.   HWND ip = ::GetDlgItem(this->m_hWnd,IDC_log);
  229.   if (ip) {
  230.     int w,h;
  231.     RECT rect;
  232.     ::GetWindowRect(ip,&rect);
  233.     // screen coord -> client coord
  234.     POINT a,b;
  235.     a.x=rect.left; a.y=rect.top; b.x=rect.right; b.y=rect.bottom;
  236.     ::ScreenToClient(this->m_hWnd,&a); ::ScreenToClient(this->m_hWnd,&b);
  237.     rect.left=a.x; rect.top=a.y; rect.right=b.x; rect.bottom=b.y;
  238.     w = max(cx - rect.left,320);
  239.     h = max(cy - rect.top,200);
  240.     ::SetWindowPos(ip,NULL,0,0,w,h,SWP_NOZORDER|SWP_NOMOVE|SWP_NOOWNERZORDER);
  241.   }
  242. }
  243.  
  244.  
  245. void Ciplog::OnDestroy() 
  246. {
  247.   if (fp) {
  248.     fclose(fp);    
  249.     fp=NULL;
  250.   }
  251.     CDialog::OnDestroy();    
  252. }
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259. // ------------------------------------------------------------
  260. // TOOL TIPS
  261. //
  262. // ajouter dans le .cpp:
  263. // remplacer les deux Wid1:: par le nom de la classe::
  264. // dans la message map, ajouter
  265. // ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  266. // dans initdialog ajouter
  267. // EnableToolTips(true);     // TOOL TIPS
  268. //
  269. // ajouter dans le .h:
  270. // char* GetTip(int id);
  271. // et en generated message map
  272. // afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
  273. BOOL Ciplog::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  274. {
  275.   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  276.   UINT_PTR nID =pNMHDR->idFrom;
  277.   if (pTTT->uFlags & TTF_IDISHWND)
  278.   {
  279.     // idFrom is actually the HWND of the tool
  280.     nID = ::GetDlgCtrlID((HWND)nID);
  281.     if(nID)
  282.     {
  283.       char* st=GetTip((int)nID);
  284.       if (st != "") {
  285.         pTTT->lpszText = st;
  286.         pTTT->hinst = AfxGetResourceHandle();
  287.         return(TRUE);
  288.       }
  289.     }
  290.   }
  291.   return(FALSE);
  292. }
  293. char* Ciplog::GetTip(int ID)
  294. {
  295.   switch(ID) {
  296.     case IDC_logtype:  return LANG(LANG_E1 /*"View error and warning reports"*/); break;
  297.     case IDC_logtype2: return LANG(LANG_E2 /*"View info report"*/); break;
  298.     case IDC_FIND:     return LANG(LANG_E8); break; 
  299.     //case IDOK:         return LANG(LANG_E3 /*"Close the log window"*/); break;
  300.     //case : return ""; break;
  301.   }
  302.   return "";
  303. }
  304. // TOOL TIPS
  305. // ------------------------------------------------------------
  306.  
  307.  
  308. // Appel aide
  309. void Ciplog::OnHelpInfo2() {
  310.   (void) OnHelpInfo(NULL);
  311. }
  312.  
  313. BOOL Ciplog::OnHelpInfo(HELPINFO* dummy) 
  314. {
  315.   //return CDialog::OnHelpInfo(pHelpInfo);
  316.   HtsHelper->Help();
  317.   return true;
  318.   //AfxGetApp()->WinHelp(0,HELP_FINDER);    // Index du fichier Hlp
  319.   //return true;
  320. }
  321.  
  322. void Ciplog::Onchangelog() 
  323. {
  324.   if (type_log)
  325.     type_log=0;
  326.   else
  327.     type_log=1;  
  328. }
  329.  
  330. void Ciplog::OnTimer(UINT nIDEvent) 
  331. {
  332.   AffLogRefresh();
  333.     CDialog::OnTimer(nIDEvent);
  334. }
  335.  
  336. void Ciplog::StartTimer() {
  337.   if (!timer) {
  338.     timer=SetTimer(WM_TIMER,100,NULL);
  339.   }
  340. }
  341. void Ciplog::StopTimer() {
  342.   if (timer) {
  343.     KillTimer(timer);
  344.     timer=0;
  345.   }
  346. }
  347.  
  348. void Ciplog::OnSelchangeHideinfo() 
  349. {
  350.   int r=m_ctl_hideinfo.GetCurSel();
  351.   switch(r) {
  352.   case CB_ERR : break;  // pas de sΘlection
  353.   default:
  354.     type_filter=r;
  355.   break;
  356.   }
  357. }
  358.  
  359. void Ciplog::OnFind() 
  360. {
  361.   CWaitCursor wait;
  362.   CString find;
  363.   GetDlgItemText(IDC_FINDSTR,find);
  364.   find.MakeLower();
  365.   if (find.GetLength()) {
  366.     CString data;
  367.     GetDlgItemText(IDC_log,data);
  368.     data.MakeLower();
  369.     int pos=data.Find(find);
  370.     if (pos>=0) {
  371.       //m_ctl_iplog.SetScrollPos(SB_VERT,m_ctl_iplog.LineFromChar(pos));
  372.       m_ctl_iplog.Clear();
  373.       //m_ctl_iplog.SetSel(pos,pos+100);
  374.       m_ctl_iplog.SendMessage(EM_SETSEL,0,pos);
  375.       m_ctl_iplog.SendMessage(EM_EXSETSEL,0,(LPARAM) (CHARRANGE FAR *) pos);
  376.       m_ctl_iplog.SendMessage(EM_SCROLLCARET,0,0);
  377.       m_ctl_iplog.SendMessage(EM_SETSEL,-1,-1);
  378.  
  379.       //m_ctl_iplog.RedrawWindow();
  380.     }
  381.   }
  382. }
  383.